<?php
/***************************************************************
*  Copyright notice
*  (c) 2009, jianyuzhu@gmail.com
*  All rights reserved
*  This script is part of the PPEMI project.
***************************************************************/

//
if( $action == 'updatesetting' ) {
	$data_array = array();
	foreach($_POST as $key => $value) {
		if( strstr($key, 'field_') !== false ) {
			$data_array[substr($key, strlen('field_'))] = $value;
		}
	}
	if( is_array($data_array) ) {
		if( isset($data_array['shopping_countryid']) ) {
			include_once(CONFIG_PATH . CONFIG_DIR_CLASSES . 'core.country.class.php');
			$countryObj = new CoreCountry();
			$country = $countryObj->getCountryISO($SETTINGS['shopping_countryid']);
			$data_array['shopping_countryname'] = $country['name'];
		}
		//
		if( isset($data_array['shopping_zoneid']) && $data_array['shopping_zoneid'] > 0 ) {
			if( isset($data_array['shopping_zoneid_text']) ) {
				unset($data_array['shopping_zoneid_text']);
			}
			include_once(CONFIG_PATH . CONFIG_DIR_CLASSES . 'core.zone.class.php');
			$zoneObj = new CoreZoneBase();
			$zone = $zoneObj->getItem($data_array['shopping_zoneid']);
			$data_array['shopping_zonename'] = $zone['zones_name'];
			$data_array['shopping_zonecode'] = $zone['zones_code'];
		} else {
			if( isset($data_array['shopping_zoneid_text']) ) {
				$data_array['shopping_zonename'] = $data_array['shopping_zoneid_text'];
				unset($data_array['shopping_zoneid_text']);
			} else {
				$data_array['shopping_zonename'] = '';
			}
			$data_array['shopping_zoneid'] = '';
			$data_array['shopping_zonecode'] = '';
		}
		//
		foreach($data_array as $key => $value) {
			$settingObj->updateItemB($key, $value);
		}
	}
	//
	$settingObj->cacheclean();
	//
	$feObj->redirect($request_path);
}

//
$feObj->content_wrap['mainpart'] = $type;
echo $feObj->display('pagelayout/pagelayout_admin_setting.tpl');
//
?>